package spring.superrun.record.mvc.entity;

import spring.superrun.record.mvc.dto.UserInfoAddDto;
import spring.superrun.record.mvc.dto.UserInfoUpdateDto;
import spring.superrun.record.mvc.dto.WeChatInfoUpdateDto;
import spring.superrun.record.mvc.dto.WeChatMinLoginDto;
import spring.superrun.tool.newid.NewIdByUUId;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * (SuperrunUserinfos)实体类
 *
 * @author makejava
 * @since 2021-06-18 08:33:25
 */
public class SuperrunUserinfos implements Serializable {

    public SuperrunUserinfos(){
        id="WX"+NewIdByUUId.GetUUIDNoMinus();//生成id
        createtime =new Date();
        IsUpdateOtherInfo =VerifyOtherInfo();
    }
    private static final long serialVersionUID = 431869387978893274L;
    /**
     * id
     */
    private String id;
    /**
     * 微信昵称
     */
    private String nickname;
    /**
     * 微信头像
     */
    private String avatarurl;
    /**
     * 创建时间
     */
    private Date createtime;
    /**
     * 用户在本平台唯一id
     */
    private String unionid;
    /**
     * 专业名称
     */
    private String majorname;
    /**
     * 班级号
     */
    private String classnumber;
    /**
     * 男/女
     */
    private String sex;

    private String openid;
    /**
     * 姓名
     */
    private String chinesename;
    /**
     * 排名信息
     */
    private SuperrunRecordranking ranking;
    /**
     * 打卡信息
     */
    private List<SuperrunRunrecords> records;
    /**
     * 保存微信登录信息
     * @param model
     * @param openId
     */
    public void Save(WeChatMinLoginDto model, String openId){
        setNickname(model.getNickName());
        setAvatarurl(model.getAvatarUrl());
        setSex(model.getSex());
        setOpenid(openId);

    }
    /**
     * 判断昵称和头像都不为空
     * @param nickName
     * @param avatarUrl
     * @return
     */
    public boolean VerityNickNameAndLogo(String nickName, String avatarUrl){
        return nickName.isEmpty()||avatarUrl.isEmpty();
    }
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getAvatarurl() {
        return avatarurl;
    }

    public void setAvatarurl(String avatarurl) {
        this.avatarurl = avatarurl;
    }

    public Date getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }

    public String getUnionid() {
        return unionid;
    }

    public void setUnionid(String unionid) {
        this.unionid = unionid;
    }

    public String getMajorname() {
        return majorname;
    }

    public void setMajorname(String majorname) {
        this.majorname = majorname;
    }

    public String getClassnumber() {
        return classnumber;
    }

    public void setClassnumber(String classnumber) {
        this.classnumber = classnumber;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getOpenid() {
        return openid;
    }

    public void setOpenid(String openid) {
        this.openid = openid;
    }

    public String getChinesename() {
        return chinesename;
    }

    public void setChinesename(String chinesename) {
        this.chinesename = chinesename;
    }

    public SuperrunUserinfos Add(UserInfoAddDto dto) {
        setAvatarurl(dto.getAvatarurl());
        setChinesename(dto.getChinesename());
        setClassnumber(dto.getClassnumber());
        setMajorname(dto.getMajorname());
        setNickname(dto.getNickname());
        setUnionid(dto.getUnionid());
        setCreatetime(new Date());
        setId("WX"+NewIdByUUId.GetUUIDNoMinus());//生成id
        return this;
    }

    public SuperrunUserinfos Update(UserInfoUpdateDto dto) {
        setChinesename(dto.getChinesename());
        setClassnumber(dto.getClassnumber());
        setMajorname(dto.getMajorname());
        return this;
    }

    public boolean VerifyOtherInfo()
    {
        if(null ==majorname||null ==classnumber||null==chinesename){
            return false;
        }

        return  !majorname.isEmpty() && !classnumber.isEmpty() && !chinesename.isEmpty();
    }
    /// <summary>
    /// 是否更新了其他信息
    /// </summary>
    public boolean IsUpdateOtherInfo=false;

    public void SaveOtherInfosNoSex(WeChatInfoUpdateDto dto) {
        setMajorname(dto.getMajorName());
        setClassnumber(dto.getClassNumber());
        setChinesename(dto.getChineseName());
    }

    public SuperrunRecordranking getRanking() {
        return ranking;
    }

    public void setRanking(SuperrunRecordranking ranking) {
        this.ranking = ranking;
    }

    public List<SuperrunRunrecords> getRecords() {
        return records;
    }

    public void setRecords(List<SuperrunRunrecords> records) {
        this.records = records;
    }
}
